package com.css.fxfzdpzs.modules.home.repository.impl;

import com.css.fxfzdpzs.modules.home.entity.HomeSys;
import com.css.fxfzdpzs.modules.home.entity.HomeSysProvince;
import com.css.fxfzdpzs.modules.home.repository.HomeRepository;
import com.css.fxfzdpzs.util.PlatformObjectUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author y1fan
 * @description
 */
@Repository
public class HomeRepositoryImpl implements HomeRepository {

    @Resource
    JdbcTemplate jdbcTemplate;

    @Resource
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public HomeSys getHomeSys() {
        String sql = "select * from sys_home ";
        List<HomeSys> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(HomeSys.class));
        if (PlatformObjectUtils.isEmpty(list)){
            return null;
        }else {
            return list.get(0);
        }
    }

    @Override
    public List<HomeSysProvince> getHomeProvince() {
        String sql = "select * from sys_home_province   order by num  DESC  LIMIT 5 OFFSET 0 ";
        List<HomeSysProvince> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(HomeSysProvince.class));
        return list;
    }
}
